home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
- ** $Id: qrect.h,v 2.7 1998/07/03 00:09:40 hanord Exp $
- **
- ** Definition of QRect class
- **
- ** Created : 931028
- **
- ** Copyright (C) 1992-1998 Troll Tech AS. All rights reserved.
- **
- ** This file is part of Qt Free Edition, version 1.40.
- **
- ** See the file LICENSE included in the distribution for the usage
- ** and distribution terms, or http://www.troll.no/free-license.html.
- **
- ** IMPORTANT NOTE: You may NOT copy this file or any part of it into
- ** your own programs or libraries.
- **
- ** Please see http://www.troll.no/pricing.html for information about
- ** Qt Professional Edition, which is this same library but with a
- ** license which allows creation of commercial/proprietary software.
- **
- *****************************************************************************/
-
- #ifndef QRECT_H
- #define QRECT_H
-
- #ifndef QT_H
- #include "qsize.h"
- #endif // QT_H
-
-
- class QRect // rectangle class
- {
- public:
- QRect() { x1 = y1 = 0; x2 = y2 = -1; }
- QRect( const QPoint &topleft, const QPoint &bottomright );
- QRect( const QPoint &topleft, const QSize &size );
- QRect( int left, int top, int width, int height );
-
- bool isNull() const;
- bool isEmpty() const;
- bool isValid() const;
- QRect normalize() const;
-
- int left() const;
- int top() const;
- int right() const;
- int bottom() const;
- int x() const;
- int y() const;
- void setLeft( int pos );
- void setTop( int pos );
- void setRight( int pos );
- void setBottom( int pos );
- void setX( int x );
- void setY( int y );
-
- QPoint topLeft() const;
- QPoint bottomRight() const;
- QPoint topRight() const;
- QPoint bottomLeft() const;
- QPoint center() const;
-
- void rect( int *x, int *y, int *w, int *h ) const;
- void coords( int *x1, int *y1, int *x2, int *y2 ) const;
-
- void moveTopLeft( const QPoint &p );
- void moveBottomRight( const QPoint &p );
- void moveTopRight( const QPoint &p );
- void moveBottomLeft( const QPoint &p );
- void moveCenter( const QPoint &p );
- void moveBy( int dx, int dy );
-
- void setRect( int x, int y, int w, int h );
- void setCoords( int x1, int y1, int x2, int y2 );
-
- QSize size() const;
- int width() const;
- int height() const;
- void setWidth( int w );
- void setHeight( int h );
- void setSize( const QSize &s );
-
- bool contains( const QPoint &p, bool proper=FALSE ) const;
- bool contains( const QRect &r, bool proper=FALSE ) const;
- QRect unite( const QRect &r ) const;
- QRect intersect( const QRect &r ) const;
- bool intersects( const QRect &r ) const;
-
- friend bool operator==( const QRect &, const QRect & );
- friend bool operator!=( const QRect &, const QRect & );
-
- private:
- #if defined(_OS_MAC_)
- QCOORD y1;
- QCOORD x1;
- QCOORD y2;
- QCOORD x2;
- #else
- QCOORD x1;
- QCOORD y1;
- QCOORD x2;
- QCOORD y2;
- #endif
- };
-
- bool operator==( const QRect &, const QRect & );
- bool operator!=( const QRect &, const QRect & );
-
- /*****************************************************************************
- QRect stream functions
- *****************************************************************************/
-
- QDataStream &operator<<( QDataStream &, const QRect & );
- QDataStream &operator>>( QDataStream &, QRect & );
-
-
- /*****************************************************************************
- QRect inline member functions
- *****************************************************************************/
-
- inline QRect::QRect( int left, int top, int width, int height )
- {
- x1 = (QCOORD)left;
- y1 = (QCOORD)top;
- x2 = (QCOORD)(left+width-1);
- y2 = (QCOORD)(top+height-1);
- }
-
- inline bool QRect::isNull() const
- { return x2 == x1-1 && y2 == y1-1; }
-
- inline bool QRect::isEmpty() const
- { return x1 > x2 || y1 > y2; }
-
- inline bool QRect::isValid() const
- { return x1 <= x2 && y1 <= y2; }
-
- inline int QRect::left() const
- { return x1; }
-
- inline int QRect::top() const
- { return y1; }
-
- inline int QRect::right() const
- { return x2; }
-
- inline int QRect::bottom() const
- { return y2; }
-
- inline int QRect::x() const
- { return x1; }
-
- inline int QRect::y() const
- { return y1; }
-
- inline void QRect::setLeft( int pos )
- { x1 = (QCOORD)pos; }
-
- inline void QRect::setTop( int pos )
- { y1 = (QCOORD)pos; }
-
- inline void QRect::setRight( int pos )
- { x2 = (QCOORD)pos; }
-
- inline void QRect::setBottom( int pos )
- { y2 = (QCOORD)pos; }
-
- inline void QRect::setX( int x )
- { x1 = (QCOORD)x; }
-
- inline void QRect::setY( int y )
- { y1 = (QCOORD)y; }
-
- inline QPoint QRect::topLeft() const
- { return QPoint(x1, y1); }
-
- inline QPoint QRect::bottomRight() const
- { return QPoint(x2, y2); }
-
- inline QPoint QRect::topRight() const
- { return QPoint(x2, y1); }
-
- inline QPoint QRect::bottomLeft() const
- { return QPoint(x1, y2); }
-
- inline QPoint QRect::center() const
- { return QPoint((x1+x2)/2, (y1+y2)/2); }
-
- inline int QRect::width() const
- { return x2 - x1 + 1; }
-
- inline int QRect::height() const
- { return y2 - y1 + 1; }
-
- inline QSize QRect::size() const
- { return QSize(x2-x1+1, y2-y1+1); }
-
-
- #endif // QRECT_H
-